﻿<UserControl x:Class="My.CodePlex.TFSExplorer.SourceTreeControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:My.CodePlex.TFSExplorer"
    xmlns:converters="clr-namespace:My.CodePlex.TFSExplorer.Utilities.Converters"
    xmlns:controls="clr-namespace:My.CodePlex.TFSExplorer.Controls">
    <Grid>
        
        <Grid.Resources>
            <DataTemplate x:Key="ListViewHeaderTemplateAscendingSorting" >
                <Grid x:Name="HeaderTemplateSortAscGrid">
                    <Grid.ColumnDefinitions >
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width ="Auto" />
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Column ="0"  HorizontalAlignment="Center" VerticalAlignment ="Center" x:Name ="HeaderText" TextTrimming="CharacterEllipsis" TextWrapping ="Wrap" Text="{Binding}" ToolTipService.ToolTip ="{Binding}" />
                    <Path x:Name="arrow" Grid.Column="1" Opacity="0.7" Fill="Gray" VerticalAlignment="Center" StrokeThickness = "1" Data = "M 5,10 L 15,10 L 10,5 L 5,10" />
                </Grid>
            </DataTemplate>
            <DataTemplate x:Key="ListViewHeaderTemplateDescendingSorting">
                <Grid>
                    <Grid.ColumnDefinitions >
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width ="Auto" />
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Column ="0"  HorizontalAlignment="Center" VerticalAlignment ="Center" x:Name ="HeaderText" TextTrimming="CharacterEllipsis" TextWrapping ="Wrap" Text="{Binding }" ToolTipService.ToolTip ="{Binding}"/>
                    <Path x:Name="arrow" Grid.Column ="1" VerticalAlignment ="Center" StrokeThickness = "1" Opacity ="0.7" Fill ="Gray" Data = "M 5,5 L 10,10 L 15,5 L 5,5" />
                </Grid>
            </DataTemplate>
            <DataTemplate x:Key="ListViewHeaderTemplateNoSorting">
                <DockPanel>
                    <TextBlock HorizontalAlignment="Center" TextTrimming="CharacterEllipsis" VerticalAlignment ="Center" TextWrapping ="Wrap" Text="{Binding }" ToolTipService.ToolTip ="{Binding}" />
                </DockPanel>
            </DataTemplate>
        </Grid.Resources>
        
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        
        <!-- Source folder view -->
        <Grid Grid.Column="0" Margin="0,0,5,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="27" />
                <RowDefinition />
            </Grid.RowDefinitions>          
            
            <Label Content="Folders" HorizontalAlignment="Left" />
            <!--<Grid Grid.Row="1" Background="White">
                <local:WaitCursor x:Name="WaitCursor" Width="20" Height="20" />
            </Grid>-->
            <TreeView x:Name="SourceFolderView" Grid.Row="1">
                <TreeView.ItemTemplate>
                    <HierarchicalDataTemplate ItemsSource="{Binding Path=Items}">
                        <StackPanel Orientation="Horizontal">
                            <Image Source="{Binding ImgUri, Converter={converters:PathToImageConverter}}" />
                            <TextBlock Text="{Binding Path=Name}" />
                        </StackPanel>
                    </HierarchicalDataTemplate>
                </TreeView.ItemTemplate>
                <TreeView.ContextMenu>
                    <ContextMenu Name="SourceFolderViewContextMenu">
                        <MenuItem Header="Get Latest Version" Click="GetLatestFolderVersionClick">
                            <MenuItem.Icon>
                                <Image Source="pack://application:,,,/My.CodePlex.TFSExplorer;component/Images/GetLatestVersion.png" />
                            </MenuItem.Icon>
                        </MenuItem>
                        <Separator/>
                        <MenuItem Header="Checkout Folder Contents" Click="CheckoutFolderMenuItemClick">
                            <MenuItem.Icon>
                                <Image Source="pack://application:,,,/My.CodePlex.TFSExplorer;component/Images/Checkout.png" />
                            </MenuItem.Icon>
                        </MenuItem>
                        <MenuItem Header="Open in Explorer" Name="OpenExplorerMenuItem" Click="OpenExplorerMenuItemClick">
                            <MenuItem.Icon>
                                <Image Source="pack://application:,,,/My.CodePlex.TFSExplorer;component/Images/FolderOpen.png" />
                            </MenuItem.Icon>
                        </MenuItem>
                    </ContextMenu>
                </TreeView.ContextMenu>
            </TreeView>
        </Grid>
        
        <GridSplitter Width="3" />
        <!-- Source folder contents view -->
        <Grid Grid.Column="1" Margin="0,0,5,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="27" />
                <RowDefinition />
            </Grid.RowDefinitions>
            <StackPanel Orientation="Horizontal">
                <Label Content="Folder Path: " HorizontalAlignment="Left" />
                <Label Name="FolderPathLabel" HorizontalAlignment="Left" />
            </StackPanel>
            <ListView x:Name="SourceFileView" Grid.Row="1"
                    VirtualizingStackPanel.IsVirtualizing="True"
                    local:ListViewSorter.CustomListViewSorter="My.CodePlex.TFSExplorer.SourceItemComparer"
                    PreviewMouseRightButtonDown="SourceFileView_PreviewMouseRightButtonDown">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Width="Auto" Header="Name">
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                        <Grid Margin="6,0,6,0" >
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width ="20" />
                                                <ColumnDefinition Width ="*" />
                                            </Grid.ColumnDefinitions>
                                            <Image VerticalAlignment ="Center" Width="16" Source="{Binding ImgSource}" />
                                            <TextBlock Text="{Binding Name}" Foreground="{Binding IsCheckedout, Converter={converters:BoolToBrushConverter}}" Grid.Column="1" TextTrimming="CharacterEllipsis" VerticalAlignment ="Center" />
                                        </Grid>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn Width="Auto" Header="Checkin Date" DisplayMemberBinding="{Binding CheckinDate}"  />
                        <GridViewColumn Width="Auto" Header="IsServerVersion" DisplayMemberBinding="{Binding IsLatestVersion}"  />
                        <GridViewColumn Width="Auto" Header="Client" DisplayMemberBinding="{Binding Client}"  />
                    </GridView>
                </ListView.View>
                <ListView.ContextMenu>
                    <ContextMenu Name="SourceFileViewContextMenu">
                        <MenuItem Header="View..." />
                        <Separator/>
                        <MenuItem Header="Get Latest Version" Click="GetLatestVersionClick">
                            <MenuItem.Icon>
                                <Image Source="pack://application:,,,/My.CodePlex.TFSExplorer;component/Images/GetLatestVersion.png" />
                            </MenuItem.Icon>
                        </MenuItem>
                        <Separator/>
                        <MenuItem Header="Checkout" Name="CheckoutMenuItem" Click="CheckoutMenuItemClick">
                            <MenuItem.Icon>
                                <Image Source="pack://application:,,,/My.CodePlex.TFSExplorer;component/Images/Checkout.png" />
                            </MenuItem.Icon>
                        </MenuItem>
                        <MenuItem Header="Checkin" Name="CheckinMenuItem" Click="CheckinMenuItemClick">
                            <MenuItem.Icon>
                                <Image Source="pack://application:,,,/My.CodePlex.TFSExplorer;component/Images/Checkin.png" />
                            </MenuItem.Icon>
                        </MenuItem>
                        <MenuItem Header="Undo Checkout" Name="UndoCheckoutMenuItem" Click="UndoCheckoutMenuItemClick">
                            <MenuItem.Icon>
                                <Image Source="pack://application:,,,/My.CodePlex.TFSExplorer;component/Images/Undo.png" />
                            </MenuItem.Icon>
                        </MenuItem>
                    </ContextMenu>
                </ListView.ContextMenu>
            </ListView>
        </Grid>

        <GridSplitter Width="3" Grid.Column="1" />
        <!-- History view -->
        <Grid Grid.Column="2">
            <Grid.RowDefinitions>
                <RowDefinition Height="27" />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Label x:Name="HistoryViewLabel" Content="History" HorizontalAlignment="Left" />
            <controls:HistoryViewControl Grid.Row="1" x:Name="SourceHistoryView" />
        </Grid>
    </Grid>
</UserControl>
